import os
import psutil
from phot_server.server_config import minio_config
from phot_server.server_config import global_config


def start_minio_server():
    # os.environ["MINIO_ROOT_USER"] = platform.node()
    # os.environ["MINIO_ROOT_PASSWORD"] = platform.node()
    minio_running_flag = False
    pids = psutil.pids()
    for pid in pids:
        if psutil.Process(pid).name() == "minio.exe":
            minio_running_flag = True
    if not minio_running_flag:
        minio_start_cmd = global_config.BASE_ROOT + "/database/start_minio.sh {exe_path} {blucket_root} \"{console_address}\" \"{address}\"" \
            .format(exe_path=minio_config.MINIO_EXE_PATH,
                    blucket_root=minio_config.MINIO_BLUCKET_ROOT,
                    console_address=minio_config.MINIO_CONSOLE_ADDRESS,
                    address=minio_config.MINIO_ADDRESS)
        os.system(minio_start_cmd)


if __name__ == '__main__':
    start_minio_server()
